<?php

abstract class AbstractWidget extends Object
{
    protected $view;

    /**
     * Parameters
     *
     * @var array
     */
    protected $params;

	public function __construct()
	{
		parent::__construct();
	}

    /**
     * Initializes component
     *
     * @return void
     */
    public function init($params = null)
    {
        if ($params) {
            if (is_array( $params ) && !empty($params)) {
                $this->params = $params;
            } else {
                throw new Exception('Params are not set or not array');
            }
        }

        $this->view = Smarty2::Singleton();
        $this->view->assign('component_name', $this->objectName);

        /*$this->addScripts($this->initScript());
        $this->addStyles($this->initStyle());*/
    }
    
    public function render($template)
    {        
        $olddir = $this->view->template_dir;
        $name = strtolower(get_class($this));
        $path = dirname( __FILE__ ) . '/' . $name;

        if( !file_exists($path.'/'.$template) ) {
            throw new Exception('Template '.$template.' not found in '.$path);
        }
        $this->view->template_dir = $path;
        $ret = $this->view->fetch($template);
        $this->view->template_dir = $olddir;
        return $ret;
    }

    abstract function display();
}